package net.dipper.tankwar.editor.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.dipper.tankwar.core.config.ConfigItem;

public class ObjectList extends JPanel implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel label;
	private ArrayList<ActionListener> listeners;
	
	public ObjectList(String name, HashMap<Byte, ConfigItem> config) throws IOException{
		listeners = new ArrayList<ActionListener>();
		
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));		
		this.label = new JLabel(name);
		add(this.label);
		
		for(ConfigItem conf : config.values()){
			ObjectListItem item = new ObjectListItem(this, conf);
			item.addActionListener(this);
			add(item);
		}
	}
	
	public void addActionListener(ActionListener listener){
		this.listeners.add(listener);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		for(ActionListener listener : listeners){
			listener.actionPerformed(e);
		}
	}
}
